package com.ms.qw.format;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * User: gmc
 * Date: 23/10/12
 */
public class DateFormatter implements Formatter<Date> {

    public static final Formatter DATE_FORMATTER = new DateFormatter("dd/MM/yyyy");
    public static final Formatter DATE_TIME_FORMATTER = new DateFormatter("dd/MM/yyyy HH:mm");
    public static final Formatter TIME_FORMATTER = new DateFormatter("HH:mm");

    private SimpleDateFormat format = null;

    public DateFormatter(String formatPattern) {
        this.format = new SimpleDateFormat(formatPattern);
    }


    public String print(Date value) {
        return format.format(value);
    }

    public Date parse(String text) throws ParseException {
        if ("".equals(text)) {
            return null;
        }
        return format.parse(text);
    }


}
